<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
	array('title'=>'行业列表','op'=>'list'),
	array('title'=>'添加行业','op'=>'edit'),
);
set_html('tabs',$tabs);
/*******list*******/
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 20;
	$params=array('uniacid'=>array(0,$_SESSION['uniacid']));
	if($_RQ['title']){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$fields=array('id','uniacid','title','display');
	$list=pdo_getslice('jy_business_card_industry',$params,array($pindex,$psize),$total,$fields,'','id desc');
	
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['htmls']=array('type'=>'list','list'=>array(
		'data'=>'list',
		'edit'=>false,
		'del_one'=>false,
		'del_op'=>'list_del',
		'del_title'=>'删除',
		'delall'=>false,
		'del_message'=>'确定要删除吗？',
		'pagelist'=>true,
		'list'=>array(
			
			array(
				array('type'=>'string','name'=>'display','title'=>'排序',),
			),
			array(
				array('type'=>'string','name'=>'title','title'=>'行业名称',),
			),
		),
		'action'=>array(
			array('type'=>'post','op'=>'list_del','title'=>'删除','show'=>array('uniacid >'=>0)),
			array('type'=>'href','op'=>'edit','title'=>'编辑','show'=>array('uniacid >'=>0)),
		),
	),'search_one'=>array('add'=>true,'name'=>'title',),);

	
	set_html('title','音乐列表');
	exi($return);
}
if($_RQ['op']=='list_del'){
	$dels=array();
	if($_RQ['del']){
		$dels=str_2_array($_RQ['del']);
	}
	if($_RQ['id']){
		$dels[]=intval($_RQ['id']);
	}
	if(empty($dels)){
		exi('没有选择要删除的项目！','error');
	}
	foreach($dels as $id){
		pdo_delete('jy_business_card_industry',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		
	}
	exi('删除成功！');
}
/*******list*******/
/*******edit*******/
if($_RQ['op']=='edit'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$data=array_fields(array('title','display'),$post);

		if(!$id){
			$data['uniacid']=$_SESSION['uniacid'];
			pdo_insert('jy_business_card_industry',$data);
		}else{
			pdo_update('jy_business_card_industry',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
		
		exi('操作成功！','','list');
	}
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_business_card_industry',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$item=array('title'=>'');
	}
	$return['item']=$item;
	$return['htmls']=array('type'=>'edit','desc'=>'编辑音乐信息','edit'=>array(
		array('title'=>'名称','name'=>'title','type'=>'string',),
		array('title'=>'排序','name'=>'display','type'=>'string','help'=>'填写数字，数值越大越靠前'),
	),);
	set_html('title','音乐编辑');
	exi($return);
}
/*******edit*******/
/*******op*******/
exi('访问的页面功能不存在！','error');